package implementation.sort.MergeSort;


import anaydis.sort.SorterType;
import com.sun.istack.internal.NotNull;

import java.util.Comparator;
import java.util.List;

public class MergeTopDown extends AbstractMergeSort {

    public MergeTopDown() {
        super(SorterType.MERGE);
    }

    public <T> void sort(@NotNull Comparator<T> tComparator, @NotNull List<T> ts) {
        sort(tComparator, ts, 0, ts.size() - 1);
    }

    private <T> void sort(Comparator<T> tComparator, List<T> ts, int start, int end) {
        if (start >= end) {
            return;
        }
        int half = (end + start) / 2;
        sort(tComparator, ts, start, half);
        sort(tComparator, ts, half + 1, end);
        merge(tComparator,ts, start, half, end);
    }


}
